//
//  TalkSecViewController.m
//  A段项目
//
//  Created by dlios on 15/7/22.
//  Copyright (c) 2015年 dlios. All rights reserved.
//

#import "TalkSecViewController.h"
#import "HeaderView.h"
#import "BaseHeader.h"
#import "TalkSecTableViewCell.h"
#import <SDWebImage/UIImageView+WebCache.h>

@interface TalkSecViewController ()<UITableViewDataSource, UITableViewDelegate>
//@property (nonatomic, retain) UITableView *table;

@end

@implementation TalkSecViewController

- (void)dealloc
{
    [_dic release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        self.dic = [NSMutableDictionary dictionary];
    }
    return  self;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    [self createTable];
    // Do any additional setup after loading the view.
}

- (void)createTable
{
    UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeidth - 100) style:UITableViewStylePlain];
    [table registerClass:[TalkSecTableViewCell class] forCellReuseIdentifier:@"a"];
    table.rowHeight = 100;
    table.dataSource = self;
    table.delegate = self;
    [self.view addSubview:table];
    [table release];
    
    HeaderView *head = [[HeaderView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeidth / 3)];
    [head.userAvatar sd_setImageWithURL:[_dic objectForKey:@"userAvatar"] placeholderImage:[UIImage imageNamed:@"1.jpg"]];
    head.userName.text = [_dic objectForKey:@"userName"];
    head.forumName.text = [_dic objectForKey:@"forumName"];
    head.content.text = [_dic objectForKey:@"content"];
    head.location.text = [_dic objectForKey:@"location"];
    head.agreeCount.text = [NSString stringWithFormat:@"%@", [_dic objectForKey:@"agreeCount"]];
    head.commentCount.text = [NSString stringWithFormat:@"%@", [_dic objectForKey:@"commentCount"]];
    table.tableHeaderView = head;
    [head release];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  [[_dic objectForKey:@"comment"] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TalkSecTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"a"];
    NSArray *arr = [_dic objectForKey:@"comment"];
    NSDictionary *dic = [arr objectAtIndex:indexPath.row];
    [cell.userAvatar sd_setImageWithURL:[dic objectForKey:@"userAvatar"] placeholderImage:[UIImage imageNamed:@"1.jpg"]];
    cell.userName.text = [dic objectForKey:@"userName"];
    cell.content.text = [dic objectForKey:@"content"];
    return cell;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
